<div id="main">
    <div id="contents">

            <fieldset>
                <legend>
                    <label sid="forwards.title"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="ip_address">
                                    <label sid="forwards.virtual_server_ipaddr"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="ipAddr" type="text" name="ipAddr" size="16">
                                <span class="x-form-tip" id="ipAddrTip"></span>
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="fromPort">
                                    <label sid="forwards.virtual_server_port_range"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="fromPort" type="text" name="fromPort" size="5">
                                -
                                <input id="toPort" type="text" name="toPort" size="5">
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="protocol">
                                    <label sid="firewall.protocol"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <select id="protocol" name="protocol">
                                    <option value="3" select="">TCP&amp;UDP</option>
                                    <option value="1">TCP</option>
                                    <option value="2">UDP</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label for="comment">
                                    <label sid="firewall.comment"></label>
                                </label>
                            </td>
                            <td class="frame_tab_right">
                                <input id="comment" type="text" maxlength="32" size="16" name="comment">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_center" colspan="2">
                                <input id="save_button_1" class="button" type="button" name="save_button_1" sid="sbutton.add">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="forwards.current_virtual_server"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table id="porttable_1" class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%"> </table>
                </div>
            </fieldset>

    </div>
</div>
<br>
<div id="helpContainer">
    <div id="help">
        <div>
            <h2>
                <label sid="share.help"></label>
            </h2>
        </div>
        <div id="helpBody">
        <dl>
            <dt class="term">
                <label sid="forwards.title"></label>
            </dt>
            <dd class="definition">
                <label sid="forwards.introduction"></label>
            </dd>

        </dl>
    </div>
    </div>
</div>
<script type="text/javascript" src="js/libTable.js"></script>
<script type="text/javascript">

    if(typeof(forwards.introduction)=="undefined"){
        $("#contents").attr("id","contents_stat");
        $("#helpContainer").hide();
    }
        var virtual_data_1 = new Array();
        var old_virtual_1=0;
        load_html();

        $.formValidator.initConfig({debug:false,submitOnce:true,submitButtonID:"save_button_1",
            onError:function(msg, obj, errorlist) {

            },
            onSuccess:function(){
                var ipAddr = $("#ipAddr").val();
                var fromPort = $("#fromPort").val();
                var toPort = $("#toPort").val();
                var protocol = $("#protocol").val();
                var comment=$("#comment").val();
                if($("#save_button_1").val()==sbutton.modify){
                    virtual_data_1[old_virtual_1][0]=ipAddr;
                    virtual_data_1[old_virtual_1][1]=fromPort;
                    virtual_data_1[old_virtual_1][2]=toPort;
                    virtual_data_1[old_virtual_1][3]=protocol;
                    virtual_data_1[old_virtual_1][4]=comment;
                }else{
                    var newarray = new Array();
                    newarray[0]=ipAddr;
                    newarray[1]=fromPort;
                    newarray[2]=toPort;
                    newarray[3]=protocol;
                    newarray[4]=comment;
                    virtual_data_1.push(newarray);
                    $("#save_button_1").val(sbutton.add);
                }
                var resultStr = JSONTostr(virtual_data_1);
                var settext='&id2327='+resultStr;
                submitform(modules["set_data"],settext,"virtual_set_main_load");
                load_html();
            }
        });
        $("#ipAddr").formValidator({
            onFocus:errmsg.Info9
        }).regexValidator({
                    regExp:regexEnum.notempty,
                    onError:errmsg.Info3
                }).regexValidator({
                    regExp:regexEnum.ip4,
                    onError:errmsg.Info1
                });



function load_html(){
	var sendtext = '&id=2327';
	DataRequest("get_json",sendtext,function(data){
		//updatecfgvalue("id2326",data["id2326"]);
		var tmparray_1 = strToJSON(data["id2327"]);
		//if(tmparray_1!=""&&tmparray_1){
		virtual_data_1 = tmparray_1;
		virtual_paint_list_1(tmparray_1);
		//}
	});
}

function virtual_paint_list_1(data){
 var data_new=new Array();
 var j=0;
  for(var i=0;i<data.length;i++){
 	var ID = parseInt(parseInt(i)+1);
  	var ipaddr = replacestr(data[i][0]);
  	var fromPort = replacestr(data[i][1]);
 	var toPort = replacestr(data[i][2]);
 	var comment = replacestr(data[i][4]);
 if(data[i][3]=="1"){
  	var protocol = "TCP";
  }else if(data[i][3]=="2"){
  	var protocol = "UDP";
  }else if(data[i][3]=="3"){
  	var protocol = "TCP&UDP";
  }else{
  	var protocol = "";
  	}
  var rport = fromPort +"-" +toPort;
  data_new.push({ID:ID,ipaddr:ipaddr,rport:rport,protocol:protocol,comment:comment});
  j = i;
 }
 var fun_arr = [{type:"modify",name:"virtual_change_1"},{type:"del",name:"virtual_del_1"}];
 var tab = new libTable(new Array(firewall.no,forwards.virtual_server_ipaddr,forwards.virtual_server_port_range,firewall.protocol,firewall.comment,msg.op),data_new,1,10);
 print_table("porttable_1",tab,fun_arr, true);
}


function virtual_change_1(id,ipaddr,rport,protocol,comment)
{
 obj = virtual_data_1[parseInt(id)-1];
 old_virtual_1 = parseInt(id)-1;
 with(obj){
  $("#ipAddr").val(ipaddr);
  $("#comment").val(comment);
	if(protocol == "TCP"){
 	 listselect("protocol","1");
  }else if(protocol == "UDP"){
 	 listselect("protocol","2");
  }else if(protocol == "TCP&UDP"){
 	 listselect("protocol","3");
  }
  if(rport.indexOf("-")>=0){
  	$("#fromPort").val(rport.split("-")[0]);
  	$("#toPort").val(rport.split("-")[1]);
  	}else if(rport!==""){
  		$("#fromPort").val(rport);
  		$("#toPort").val(rport);
  	}
 }
 $("#save_button_1").val(sbutton.modify);
}

function virtual_del_1(id,ipaddr,rport,protocol,comment){
 if(confirm(msg.confirm_del)){
// show_message("del",msg.deleting);
 virtual_data_1[parseInt(id)-1] = [];
 var resultStr = JSONTostr(virtual_data_1);
  var settext='&id2327='+resultStr;
  submitform(modules["set_data"],settext,"virtual_set_main_load");
  load_html();
 }
}

</script>

